'''
参数：1.有参数
     2.无参数

有参数：def 函数名(参数1,参数2,参数3,...):
        pass
参数 就是在调用函数时向函数中传值作用

无参数：def 函数名():
        pass
'''
import random
def generate_code(n):
    s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    code = ''
    for i in range(n):
        r = random.choice(s)
        code += r
    print(code)

generate_code(4)
# generate_code(6)

'''
1.login 带参数，n表示允许输入错误的次数
'''
# def login(n):
#     for i in range(n):
#         username = input('请输入用户名：')
#         password = input('请输入密码：')
#         if username == 'admin' and password == '1234':
#             print('登录成功')
#             break
#         else:
#             print('用户名或密码错误')
#             if i == n-1:
#                 print('输入错误次数过多，请稍后再试')
#             else:
#                 print('还有',n-i-1,'次机会')

# login(3)

'''
2.求1-n的累加和
'''
def sum(n):
    s = 0
    for i in range(1,n+1):
        s += i
    print(s)

sum(100)
print('------------------------------')

# def get_sum(a,b):
#     s = a + b
#     print(s)
#
# get_sum(1,2)
# get_sum('hello','world')

def get_sum(a,b):
    if type(a) == type(b): # if isinstance(a,int) and isinstance(b,int):
         s = a + b
         print(s)
    else:
         print('类型不一致')


# def islogin(username,password):
#     if username == 'admin' and password == '1234':
#         print('登录成功')
#     else:
#         print('登入失败')
#
# islogin('admin','1234')

def islogin(username,password,isnumber=False):
    print('是否记住密码？',isnumber)
    if username == 'admin' and password == '1234':
        print('登录成功')
    else:
        print('登入失败')

islogin('admin','1234')